package com.wyw.hemerocallis.controller;

import com.wyw.hemerocallis.common.TableId;
import com.wyw.hemerocallis.order.OrderInfo;
import com.wyw.hemerocallis.service.IOrderService;
import com.wyw.hemerocallis.vo.PageSimpleOrderDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 订单服务对外 HTTP 接口
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@Api(tags = "订单服务")
@Slf4j
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class RestOrderController {

    private final IOrderService orderService;

    @ApiOperation(
            value = "创建",
            notes = "下单（分布式事务）：创建订单 -> 扣减库存 -> 扣减余额 -> 发送物流信息",
            httpMethod = "POST"
    )
    @PostMapping("/create-order")
    public TableId createOrder(@RequestBody OrderInfo orderInfo) {
        return orderService.createOrder(orderInfo);
    }

    @ApiOperation(
            value = "订单信息",
            notes = "获取当前用户的订单信息: 带有分页",
            httpMethod = "GET"
    )
    @GetMapping("/order-detail")
    public PageSimpleOrderDetail getSimpleOrderDetailByPage(
            @RequestParam(required = false, defaultValue = "1") int page) {
        return orderService.getSimpleOrderDetailByPage(page);
    }

}
